package com.fisher.checker.db;

import android.content.Context;
import androidx.room.Room;

public class DatabaseClient {
    private static AppDatabase appDatabase;
    private static DatabaseManager databaseManager;

    public static synchronized AppDatabase getAppDatabase(Context context) {
        if (appDatabase == null) {
            appDatabase = Room.databaseBuilder(context.getApplicationContext(),
                            AppDatabase.class, "product_database")
                    .fallbackToDestructiveMigration()
                    .build();
            databaseManager = new DatabaseManager();
        }
        return appDatabase;
    }

    public static DatabaseManager getDatabaseManager(){
        if(null != databaseManager){
            return databaseManager;
        }
        databaseManager = new DatabaseManager();
        return databaseManager;
    }

    public static synchronized void closeDatabase() {
        if (appDatabase != null && appDatabase.isOpen()) {
            appDatabase.close();
            appDatabase = null;
        }
    }
}

